package com.angel.bo.common.util.thread;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 创建线程池
 */
public class AngelThreadExecutorFactory {


    /**
     * 私有的静态变量
     */
    private static ThreadPoolExecutor threadPoolExecutor = null;

    /**
      * 线程池维护线程的最少数量
      */
    private static final int SIZE_CORE_POOL = 5;

    /**
     * 线程池维护线程的最大数量
     */

    private static final int SIZE_MAX_POOL = 5;


    /**
     * 构造方法私有化
     */
    private AngelThreadExecutorFactory(){

    }


    /**
     * 返回一个线程池
     * @return ThreadPoolExecutor
     */
    public static ThreadPoolExecutor getEcgThreadPoolExecutor(){
        if(null == threadPoolExecutor){
            threadPoolExecutor = new ThreadPoolExecutor(SIZE_CORE_POOL,SIZE_MAX_POOL,60000L,
                    TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
        }
        return threadPoolExecutor;
    }

}
